{extend name="public/base" /}
{block name="title"}{$article.title} - {$sysInfo.webname}{/block} 
{block name="keywords"}{$article.keywords ?: $article.title}{/block}
{block name="description"}{$article.title},{$article.description ?? ''}{/block}
{block name="ogtitle"}<meta property="og:title" content="{$article.title} - {$sysInfo.webname}">{/block}
{block name="ogdescription"}<meta property="og:description" content="{$article.title},{$article.description ?? ''}" />{/block}
{block name="meta"}
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="{$article.create_time|date='c'}"/>
<meta property="bytedance:published_time" content="{$article.create_time|date='c'}" />
<meta property="bytedance:updated_time" content="{$article.update_time|date='c'}" />
{/block}
{block name="link"} {/block}
{block name="column"}<div class="layui-hide-xs">{include file="/public/column" /}</div>{/block}
{block name="content"}
<div class="layui-container">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12 content detail">
      <div class="fly-panel detail-box">
		    {//标题}
        <h1 style="color:{$article.title_color ?: '#333'}; margin:10px 5px 15px 5px; text-align: center;">{$article.title}</h1>

		    {//作者}
        <div class="detail-about" align="center">
          <div class="detail-hits" style="left:-30px;">
            <span>{$article.cate.catename} /</span>
            <span>{$article.user.name} /</span>
            <span class="post-time" style="padding-top: 5px;" data="{$article.create_time}">{$article.create_time}</span>
            <span>/ <i class="iconfont" title="浏览">&#xe60b;</i> {$pv}</span>
          </div>
        </div>
        <hr style="margin-bottom: 25px">
        {// 内容}
        {:hook('taoplayerdiv')}
        <div class="detail-body photos" style="font-size: 18px;line-height: 200%;" id="content">{$article.content|raw}</div>
        {if (($article.upzip !== '') || session('?user_name'))}
          <div class="">
            {notempty name="$article.upzip"}
            <button type="button" class="layui-btn layui-btn-xs" id="zip-download"><i class="layui-icon layui-icon-download-circle"></i>{:lang('download files')}: {$article.downloads}次</button>
            {/notempty}
          </div>
        {/if}

        {//解密文件}
        {empty name="passJieMi"}
        {if($article.read_type == 1)}
        <div id="jiemi" style="text-align:center">
          <button type="button" class="layui-btn layui-btn-primary"><i class="layui-icon layui-icon-password" style="font-size: 30px; color: #FF5722;"></i> 阅读请解密 </button>
        </div>
        {/if}
        {/empty}

        {notempty name="tags"}
        <div style="margin-top: 15px">标签
          {volist name="tags" id="vo" }
          <a href="{$vo.url}"><span class="layui-btn layui-btn-xs layui-btn-normal  layui-btn-radius">{$vo.name}</span></a>
          {/volist}
        </div>
        {/notempty}
          <div style="margin: 20px 0px 15px 0px; color: rgb(130, 125, 125);">
            <p style="line-height:200%;">{$sysInfo.state|raw}</p>
          </div>
        <div style="margin-top: 20px;">本文链接：<a href="{$Request.domain}{$Request.url}">{$Request.domain}{$Request.url}</a></div>
      </div>
    </div>
    {//crud管理模块}
    {include file="/public/crud" /}
  </div>
<!--底部栏-->
	<div class="site-tree-mobile-detail-bottom layui-hide-md">
		<div id="LAY_jieAdmin1" data-id="{$article['id']}"></div>
  </div> 
</div>
{include file="public/menu" /}
{/block}

{block name="script"}

{:hook('taonyeditor')}

{:hook('taoplayer')}

<script>
  var collectionFind    = "{:url('Collection/find')}",
    collection          = "{:url('collection/')}",
    articleJieset       = "{:url('Article/jieset')}",
    articleDelete       = "{:url('Article/delete')}",
    commentJiedaZan     = "{:url('Comment/jiedaZan')}",
    commentJiedaCai     = "{:url('Comment/jiedaCai')}",
    commentGetDa        = "{:url('Comment/getDa')}",
    commentUpdateDa     = "{:url('Comment/updateDa')}",
    commentJiedaDelete  = "{:url('Comment/jiedaDelete')}",
	  langCollection      = "{:lang('collection')}",
	  langCancelCollection = "{:lang('cancel collection')}";
  let taonystatus = "{:hook('taonystatus') ? 1 : 0} ";
    
  layui.use(['fly', 'face','colorpicker', 'laypage'], function(){
	var $ = layui.jquery
    ,form = layui.form
    ,fly = layui.fly
    ,colorpicker = layui.colorpicker
	,laytpl = layui.laytpl
    ,uid = layui.cache.user.uid
    ,laypage = layui.laypage;
    let LOGIN_URL = "{:url('login/index')}";

  //如果你是采用模版自带的编辑器，你需要开启以下语句来解析。

  // 编辑器插件启用状态
    if(taonystatus == 0) {
      $('.detail-body').each(function(){
        var othis = $(this), html = othis.html();
        othis.html(fly.content(html));
      });
    } else {
      $("#comment-edit").on('click',function (){
        var id = $(this).data('id');
        layer.open({
          type: 2,
          title: '修改',
          shade: 0.1,
          area: ['600px', '500px'],
          content: "{:url('comment/edit')}" + '?id=' + id
        });
      });
    }
  
  //tpl模板给发布时间赋值
  $('div.detail-hits').children('span.post-time').each(function(){
    var othis = $(this), html = othis.html();
	  var string =  laytpl('{{ d.time }}').render({
		//time: html
		time: othis.attr('data')
	});
	var posttime = layui.util.timeAgo(string, 1);
  
	othis.text(posttime);
    //console.log(othis.attr('data'));
  });
  

	//预定义颜色项
	colorpicker.render({
		elem: '#color'
		,color: '#393d49'
		,predefine: true // 开启预定义颜色
		,size: 'xs'
		,done: function(color){
			  //改变标题颜色
			  $('h1').css("color", color);
			  var id = "{$article.id}";
			  $.ajax({
				type:'post',
				url:"{:url('Article/titleColor')}",
				data:{id: id,title_color: color},
				dataType:'json',
				success:function(data){
					if(data.code == 0){
						layer.msg(data.msg,{icon:6,time:2000
						});
					} else {
						layer.open({content:data.msg,icon:5,adim:6});
					}
				}
			  });
		}
	});
  
  //评论需要登陆
  form.on('submit(user-comment)',function (data){
	var index = layer.load(1);
	var filed = data.field;
    if (uid == -1) {
			layer.msg('请先登陆',{icon:5,time:2000},function(){
                location.href = "{:url('login/index')}";
            });
        } else {
          $.ajax({
            type: "post",
            url: "{:url('article/comment')}",
            data: filed,
            dataType: "json",
            success:function (data) {
              if (data.code == 0) {
                layer.msg(data.msg,{icon:6,time:2000},function () {
                    location.reload(true);
                });
              }else {
                layer.open({title:'评论失败',content:data.msg,icon:5,anim:6});
              }
            }
          });
        }
        return false;
    });

    // 评论分页
    laypage.render({
      elem: "pages", //注意，这里的 test1 是 ID，不用加 # 号
      count: "{$article.comments_count}", //数据总数，从服务端得到
      limit: 10,
      curr: "{$page}",
      //获取起始页
      jump: function (obj, first) {
        var page = obj.curr;
        var limit = obj.limit;
        var  url = "{:url('article_detail',['id' => $article.id ,'ename' =>$article['cate']['ename']])}";
        var id = "{$article.id}";
        //首次不执行
        if (!first) {
          $.post("{:url('article/detail')}", { id: id, page: page }, function () {
            location.href = url + '?page=' + page + '#flyReply';
          });
        }
      },
    });
	
	//下载
    $('#zip-download').click(function (){
	  var id = "{$article.id}";
      $.ajax({
        type:"post",
        url:"{:url('article/download')}",
        data:{id:id},
        success:function (data) {
          location.href = "{:url('article/download',['id'=>$article.id])}"; 
        }
      });
    });

    $("#jiemi").click(function (){
      //判断登陆
      if(uid == -1){
        layer.msg('请先登录再查看', {icon: 6}, function(){location.href = LOGIN_URL})
        return false;
      }
      var id = "{$article.id}";
      layer.prompt(function(value, index, elem){
        // alert(value); //得到value
        $.post("{:url('article/jiemi')}",{id:id, art_pass:value},function (res){
          if(res.code === 0){
            layer.msg(res.msg,{icon:6,time:2000},function () {
              parent.location.reload(); //刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
            });
          } else {
            layer.msg(res.msg,{icon:5,adim:6});
          }
        });
        layer.close(index);
      });
    });

 });
</script>

{:hook('taoplyr')}

{//图片点击放大}
{include file="/public/images-click" /}

{/block}